<!DOCTYPE html>
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="description" content="tong.li&#39;s blog">
  <meta name="keyword" content="彤哥哥博客，95后技术爱好者,现就职于同程旅行/同程艺龙上海分公司，专注于互联网技术分享的平台。">
  
    <link rel="shortcut icon" href="/css/images/icon.png">
  
  <title>
    
      Linux虚拟化-KVM服务器虚拟化技术 | 彤哥哥的博客
    
  </title>
  <link href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="https://cdn.staticfile.org/nprogress/0.2.0/nprogress.min.css" rel="stylesheet">
  <link href="https://cdn.staticfile.org/highlight.js/9.12.0/styles/tomorrow-night.min.css" rel="stylesheet">
  
<link rel="stylesheet" href="/css/style.css">

  
  <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdn.staticfile.org/geopattern/1.2.3/js/geopattern.min.js"></script>
  <script src="https://cdn.staticfile.org/nprogress/0.2.0/nprogress.min.js"></script>
  
    
<script src="/js/qrious.js"></script>

  
  
  
  
    <!-- MathJax support START -->
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="https://cdn.staticfile.org/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <!-- MathJax support END -->
  


  
  
    
<script src="/js/local-search.js"></script>


<meta name="generator" content="Hexo 5.4.2"></head>
<div class="wechat-share">
  <img src="/css/images/logo.png" />
</div>
  <body>
    <header class="header fixed-header">
  <div class="header-container">
    <a class="home-link" href="/">
      <div class="logo"></div>
      <span>彤哥哥的博客</span>
    </a>
    <ul class="right-list">
      
        <li class="list-item">
          
            <a href="/" class="item-link">主页</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/series/" class="item-link">分类</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/tags/" class="item-link">标签</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/archives/" class="item-link">归档</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/project/" class="item-link">项目</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/about/" class="item-link">关于</a>
          
        </li>
      
      
        <li class="menu-item menu-item-search right-list">
    <a role="button" class="popup-trigger">
        <i class="fa fa-search fa-fw"></i>
    </a>
</li>
      
    </ul>
    <div class="menu">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </div>
    <div class="menu-mask">
      <ul class="menu-list">
        
          <li class="menu-item">
            
              <a href="/" class="menu-link">主页</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/series/" class="menu-link">分类</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/tags/" class="menu-link">标签</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/archives/" class="menu-link">归档</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/project/" class="menu-link">项目</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/about/" class="menu-link">关于</a>
            
          </li>
        
      </ul>
    </div>
    
      <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
            <span class="search-icon">
                <i class="fa fa-search"></i>
            </span>
            <div class="search-input-container">
                <input autocomplete="off" autocapitalize="off"
                    placeholder="Please enter your keyword(s) to search." spellcheck="false"
                    type="search" class="search-input">
            </div>
            <span class="popup-btn-close">
                <i class="fa fa-times-circle"></i>
            </span>
        </div>
        <div id="search-result">
            <div id="no-result">
                <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
            </div>
        </div>
    </div>
</div>
    
  </div>
</header>

    <div id="article-banner">
  <h2>Linux虚拟化-KVM服务器虚拟化技术</h2>
  <p class="post-date">2021-08-22</p>
  <div class="arrow-down">
    <a href="javascript:;"></a>
  </div>
</div>
<main class="app-body flex-box">
  <!-- Article START -->
  <article class="post-article">
    <section class="markdown-content"><h1 id="1-主流虚拟化产品"><a href="#1-主流虚拟化产品" class="headerlink" title="1. 主流虚拟化产品"></a>1. 主流虚拟化产品</h1><table>
<thead>
<tr>
<th>主流虚拟化产品</th>
<th>问世时间</th>
<th>维护企业</th>
<th>支持的虚拟化技术</th>
<th>支持的虚拟化操作系统</th>
<th>产品性质</th>
<th>性能</th>
<th>优点</th>
<th>缺点</th>
</tr>
</thead>
<tbody><tr>
<td>Red Had KVM</td>
<td>2006</td>
<td>Redhat、Ubuntu</td>
<td>全虚拟化</td>
<td>UNIX、Linux和Microsoft Windows、MacOS</td>
<td>开源</td>
<td>高</td>
<td>1. 开源免费 <br />2. 基于内核<br />3. 高性能、强稳定，操作简单<br />4. 背靠Red Had公司，社区活跃</td>
<td>1. 动态迁移以前不支持，不过最新版本已支持动态迁移</td>
</tr>
<tr>
<td>VMware WorkStation/VMware vSphere(ESXi)</td>
<td>未知</td>
<td>VMware</td>
<td>全虚拟化</td>
<td>UNIX、Linux和Microsoft Windows、MacOS(需要打补丁)</td>
<td>商业</td>
<td>一般</td>
<td>1. 市场占用率高<br />2. 虚拟化产品众多，WorkStation基于OS桌面级的虚拟化产品，VMware vSphere具体的全套虚拟化解决方案</td>
<td>1. 商业性质，需要单独付费<br /></td>
</tr>
<tr>
<td>Microsoft Hyper-V</td>
<td>2008</td>
<td>Microsoft</td>
<td>全虚拟化</td>
<td>UNIX、Linux和Microsoft Windows</td>
<td>商业</td>
<td>一般</td>
<td>1. 微软平台，安装使用简单<br />2. 桌面虚拟化对硬件要求较高</td>
<td>1. 商业性质，需要购买微软系统授权许可证，激活后可免费使用Hyper-V</td>
</tr>
<tr>
<td>XEN</td>
<td>2003</td>
<td>Citrix、Novell、Oracle、Sun、Ret Ha（RHEL5）和Virtual Iron</td>
<td>全虚拟化、半虚拟化</td>
<td>UNIX、Linux和Microsoft Windows、MacOS</td>
<td>开源</td>
<td>高</td>
<td>1. 开源免费<br />2. 性能较好</td>
<td>1. 操作复杂，学习和维护成本较高<br />2. 已被Red Had公司抛弃，顺应主流</td>
</tr>
</tbody></table>
<h1 id="2-KVM虚拟化"><a href="#2-KVM虚拟化" class="headerlink" title="2. KVM虚拟化"></a>2. KVM虚拟化</h1><h2 id="2-1-发展历程"><a href="#2-1-发展历程" class="headerlink" title="2.1 发展历程"></a>2.1 发展历程</h2><p>KVM全称是Kernel-based Virtual Machine，即基于内核的虚拟机，是采用x86硬件(Intel VT 或 AMD-V)上Linux虚拟化技术的全虚拟化解决方案。</p>
<p>KVM最初是由以色列的一个创业公司Qumranet公司的Avi Kivity开发的，作为他们的VDI产品的后台虚拟化解决方案。</p>
<p>为了简化开发，Avi Kivity并没有选择从底层开始新写一个Hypervisor，而是选择了基于Linux kernel，通过加载模块使Linux kernel本身变成一个Hypervisor。</p>
<p>2006年10月，在先后完成了基本功能、动态迁移以及主要的性能优化之后，Qumranet公司正式对外宣布KVM诞生。KVM模块的源代码被正式接纳进入Linux Kernel，成为内核源代码的一部分。</p>
<p>2008年9月4日，RedHat公司收购了Qumranet公司，用KVM替换以前XEN虚拟化方案，从而成为了KVM开源项目的新东家。</p>
<p>2010年11月，RedHat公司推出了新的企业版Red Hat Enterprise Linux 6，在这个发行版中集成了最新的KVM虚拟机，而去掉了在RHEL 5.X系列中集成的XEN。</p>
<p>对于用户来说，可选择的主流虚拟化产品也越加清晰：RedHat KVM、VMwarevSphere、Citrix Xen和微软的Hyper-V。</p>
<p>当然，KVM的发展时间太短，要在商业表现方面达到VMware或是XEN的水平，还有很长的路要走。</p>
<h2 id="2-2-模块架构"><a href="#2-2-模块架构" class="headerlink" title="2.2 模块架构"></a>2.2 模块架构</h2><p>在所谓的kvm技术中，应用到的其实有2个东西：qemu+kvm。</p>
<p>kvm负责cpu虚拟化+内存虚拟化，实现了cpu和内存的虚拟化，但kvm不能模拟其他设备；</p>
<p>qemu是模拟IO设备（网卡，磁盘），kvm加上qemu之后就能实现真正意义上服务器虚拟化。</p>
<p>libvirt则是调用kvm虚拟化技术的接口用于管理的，用libvirt管理方便，直接用qemu-kvm的接口太繁琐。</p>
<p><img src="https://ltyeamin.github.io/imgs/2021/09/20210902113436.png" alt="qeum"></p>
<img src="https://ltyeamin.github.io/imgs/2021/09/20210902112649.png" alt="KVM架构图" style="zoom:60%;" />

<img src="https://ltyeamin.github.io/imgs/2021/09/20210902112745.png" alt="libvirt" style="zoom:40%;" />



<h2 id="2-3-图形管理工具"><a href="#2-3-图形管理工具" class="headerlink" title="2.3  图形管理工具"></a>2.3  图形管理工具</h2><ul>
<li><a target="_blank" rel="noopener" href="https://zh.wikipedia.org/w/index.php?title=Kimchi&action=edit&redlink=1">Kimchi</a> – 网页版KVM虚拟化管理工具</li>
<li><a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/Virtual_Machine_Manager">Virtual Machine Manager</a> – 支持创建、编辑、启动与停止基于KVM的虚拟机，同时也支持对宿主之间的实时或冷拖拽虚拟机迁移。</li>
<li><a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/Proxmox_VE">Proxmox虚拟环境</a> – 一项开源的虚拟化管理包，包括KVM与<a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/LXC">LXC</a>。同时它还有裸机安装器、网页版远程管理界面、HA集群堆栈、统一存储、柔性网络及可选的商业支持。</li>
<li><a target="_blank" rel="noopener" href="https://zh.wikipedia.org/w/index.php?title=OpenQRM&action=edit&redlink=1">OpenQRM</a> – 用于管理不同数据中心基础设施的平台。</li>
<li><a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/GNOME_%E6%A9%9F%E6%AB%83">GNOME 机柜</a> – Linux上用于管理libvirt客户机的Gnome界面。</li>
<li><a target="_blank" rel="noopener" href="https://zh.wikipedia.org/w/index.php?title=OVirt&action=edit&redlink=1">oVirt</a> – 用于管理基于libvirt的KVM开源工具。</li>
</ul>
<h1 id="3-KVM平台搭建"><a href="#3-KVM平台搭建" class="headerlink" title="3. KVM平台搭建"></a>3. KVM平台搭建</h1><h2 id="3-1-机器列表"><a href="#3-1-机器列表" class="headerlink" title="3.1 机器列表"></a>3.1 机器列表</h2><p>实体物理机：基于Debian10.10的国产深度（Deepin V20）操作系统；IP为：192.168.1.10。</p>
<p><img src="https://ltyeamin.github.io/imgs/2021/08/20210822191213.png" alt="Deepin系统详情"></p>
<p>Microsoft Windows 10 Hyper-V虚拟机：CentOS 7；IP为：  10.108.86.250</p>
<p><img src="https://ltyeamin.github.io/imgs/2021/08/20210822191320.png" alt="CentOS7系统详情"></p>
<h2 id="3-2-虚拟化支持"><a href="#3-2-虚拟化支持" class="headerlink" title="3.2 虚拟化支持"></a>3.2 虚拟化支持</h2><h3 id="3-2-1-Linux平台"><a href="#3-2-1-Linux平台" class="headerlink" title="3.2.1 Linux平台"></a>3.2.1 Linux平台</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grep -E <span class="string">&#x27;(svm|vmx)&#x27;</span> /proc/cpuinfo   <span class="comment"># 查看当前系统是否支持CPU虚拟化，svm为AMD虚拟化，vmx是英特尔虚拟化</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>Intel的虚拟化技术称为Intel-VT(Virtual Technology)；而AMD的叫做AMD-V(AMD Virtualization，AMD主板的BIOS中称为SVM)；</p>
<p>MacOS几乎不用AMD的CPU，所以MacOS不支持AMD-V，想要安装黑苹果的朋友们选择Intel CPU。</p>
</blockquote>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">ltong@ALEX:~$ grep -E <span class="string">&#x27;(svm|vmx)&#x27;</span> /proc/cpuinfo   <span class="comment"># Deepin虚拟化支持情况</span></span><br><span class="line">flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d</span><br><span class="line">vmx flags	: vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple</span><br><span class="line">flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d</span><br><span class="line">vmx flags	: vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple</span><br><span class="line">flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d</span><br><span class="line">vmx flags	: vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple</span><br><span class="line">flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d</span><br><span class="line">vmx flags	: vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple</span><br><span class="line"></span><br><span class="line">ltong@ALEX:~$ lsmod | grep kvm</span><br><span class="line">kvm_intel             266240  0</span><br><span class="line">kvm                   839680  1 kvm_intel</span><br></pre></td></tr></table></figure>

<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">[root@lt ~]<span class="comment"># grep -E &#x27;(svm|vmx)&#x27; /proc/cpuinfo  # CentOS7嵌套虚拟化支持</span></span><br><span class="line">flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch tpr_shadow vnmi ept vpid fsgsbase bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 avx512vbmi avx512_vpopcntdq</span><br><span class="line"></span><br><span class="line">[root@lt ~]<span class="comment"># modinfo kvm_intel | grep nested   # 以下操作是开启KVM的虚拟化嵌套操作</span></span><br><span class="line">parm:           nested:bool</span><br><span class="line">[root@lt ~]<span class="comment"># cat /sys/module/kvm_intel/parameters/nested  # 如果是N的話，要改为Y</span></span><br><span class="line">N</span><br><span class="line">[root@lt ~]<span class="comment"># modprobe -r kvm-intel</span></span><br><span class="line">[root@lt ~]<span class="comment"># modprobe kvm-intel nested=1</span></span><br><span class="line">[root@lt ~]<span class="comment"># cat /sys/module/kvm_intel/parameters/nested</span></span><br><span class="line">Y</span><br><span class="line">[root@lt ~]<span class="comment"># lsmod |grep kvm # KVm环境</span></span><br><span class="line">kvm_intel             170086  0 </span><br><span class="line">kvm                   566340  1 kvm_intel</span><br><span class="line">irqbypass              13503  1 kvm</span><br></pre></td></tr></table></figure>

<h3 id="3-2-2-Windows平台"><a href="#3-2-2-Windows平台" class="headerlink" title="3.2.2 Windows平台"></a>3.2.2 Windows平台</h3><h4 id="3-2-2-1-任务管理器-性能选项查看"><a href="#3-2-2-1-任务管理器-性能选项查看" class="headerlink" title="3.2.2.1 任务管理器-性能选项查看"></a>3.2.2.1 任务管理器-性能选项查看</h4><p><img src="https://ltyeamin.github.io/imgs/2021/08/20210822191721.png"></p>
<h4 id="3-2-2-2-Hyper-V设置嵌套虚拟化支持"><a href="#3-2-2-2-Hyper-V设置嵌套虚拟化支持" class="headerlink" title="3.2.2.2 Hyper-V设置嵌套虚拟化支持"></a>3.2.2.2 Hyper-V设置嵌套虚拟化支持</h4><ol>
<li><p>以管理员身份打开Windows 10 的Powershell命令行界面</p>
</li>
<li><p>查看当前Hyper-V下的所有已安装的虚拟机</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">Windows PowerShell</span><br><span class="line">版权所有 (C) Microsoft Corporation。保留所有权利。</span><br><span class="line"></span><br><span class="line">尝试新的跨平台 PowerShell https://aka.ms/pscore6</span><br><span class="line"></span><br><span class="line"><span class="built_in">PS</span> C:\windows\system32&gt; <span class="built_in">Get-VM</span></span><br><span class="line"></span><br><span class="line">Name    State   CPUUsage(%) MemoryAssigned(M) Uptime           Status   Version</span><br><span class="line"><span class="literal">----</span>    <span class="literal">-----</span>   <span class="literal">-----------</span> <span class="literal">-----------------</span> <span class="literal">------</span>           <span class="literal">------</span>   <span class="literal">-------</span></span><br><span class="line">CentOS7 Running <span class="number">0</span>           <span class="number">1296</span>              <span class="number">00</span>:<span class="number">44</span>:<span class="number">00.1840000</span> 正常运行 <span class="number">9.0</span></span><br></pre></td></tr></table></figure></li>
<li><p>根据虚拟机名称查看虚拟机参数选项</p>
<p>​    </p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> C:\windows\system32&gt; <span class="built_in">Get-VMProcessor</span> <span class="literal">-VMName</span> CentOS7 | <span class="built_in">fl</span>   <span class="comment"># ExposeVirtualizationExtensions:False不支持虚拟化</span></span><br><span class="line">ResourcePoolName                             : Primordial</span><br><span class="line">Count                                        : <span class="number">1</span></span><br><span class="line">CompatibilityForMigrationEnabled             : False</span><br><span class="line">CompatibilityForOlderOperatingSystemsEnabled : False</span><br><span class="line">HwThreadCountPerCore                         : <span class="number">0</span></span><br><span class="line">ExposeVirtualizationExtensions               : False</span><br><span class="line">EnablePerfmonPmu                             : False</span><br><span class="line">EnablePerfmonLbr                             : False</span><br><span class="line">EnablePerfmonPebs                            : False</span><br><span class="line">EnablePerfmonIpt                             : False</span><br><span class="line">EnableLegacyApicMode                         : False</span><br><span class="line">AllowACountMCount                            : True</span><br><span class="line">Maximum                                      : <span class="number">100</span></span><br><span class="line">Reserve                                      : <span class="number">0</span></span><br><span class="line">RelativeWeight                               : <span class="number">100</span></span><br><span class="line">MaximumCountPerNumaNode                      : <span class="number">8</span></span><br><span class="line">MaximumCountPerNumaSocket                    : <span class="number">1</span></span><br><span class="line">EnableHostResourceProtection                 : False</span><br><span class="line">OperationalStatus                            : &#123;Ok, HostResourceProtectionDisabled&#125;</span><br><span class="line">StatusDescription                            : &#123;确定, 主机资源保护已禁用。&#125;</span><br><span class="line">Name                                         : 处理器</span><br><span class="line">Id                                           : Microsoft:<span class="number">63</span>F4874E<span class="literal">-DEAD-4E0D-BDD2-E7CB354A7393</span>\b637f346<span class="literal">-6a0e-4dec-af52-b</span></span><br><span class="line">                                               d70cb80a21d\<span class="number">0</span></span><br><span class="line">VMId                                         : <span class="number">63</span>f4874e<span class="literal">-dead-4e0d-bdd2-e7cb354a7393</span></span><br><span class="line">VMName                                       : CentOS7</span><br><span class="line">VMSnapshotId                                 : <span class="number">00000000</span><span class="literal">-0000-0000-0000-000000000000</span></span><br><span class="line">VMSnapshotName                               :</span><br><span class="line">CimSession                                   : CimSession: .</span><br><span class="line">ComputerName                                 : MININT<span class="literal">-5VPLROC</span></span><br><span class="line">IsDeleted                                    : False</span><br><span class="line">VMCheckpointId                               : <span class="number">00000000</span><span class="literal">-0000-0000-0000-000000000000</span></span><br><span class="line">VMCheckpointName                             :</span><br></pre></td></tr></table></figure></li>
<li><p>为当前虚拟机开启Hyper-v虚拟化支持</p>
<p>​    </p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> C:\windows\system32&gt;<span class="built_in">Set-VMProcessor</span> <span class="literal">-ExposeVirtualizationExtensions</span> <span class="variable">$true</span> <span class="literal">-VMName</span> CentOS7 <span class="comment"># 注意关闭虚拟化再执行</span></span><br></pre></td></tr></table></figure></li>
<li><p>成功开启虚拟化</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> C:\windows\system32&gt; <span class="built_in">Get-VMProcessor</span> <span class="literal">-VMName</span> CentOS7 | <span class="built_in">fl</span> | findstr ExposeVirtualizationExtensions</span><br><span class="line">ExposeVirtualizationExtensions               : True</span><br></pre></td></tr></table></figure></li>
</ol>
<h2 id="3-3-安装环境"><a href="#3-3-安装环境" class="headerlink" title="3.3 安装环境"></a>3.3 安装环境</h2><p>RedHad/CentOS/Fedora执行以下命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum -y install qemu-kvm qemu-key-tools virt-manager libvirt virt-install python-virtinst bridge-utils</span><br></pre></td></tr></table></figure>

<p>Deepin/Debain/Ubuntu执行以下命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">apt-get -y install qemu-kvm qemu-key-tools virt-manager libvirt virt-install python-virtinst bridge-utils</span><br></pre></td></tr></table></figure>

<p>安装包主要模块简介：</p>
<ul>
<li><p>qemu-kvm：主要的KVM程序包</p>
</li>
<li><p>virt-manager ：GUI虚拟机管理工具</p>
</li>
<li><p>libvirt ： C语言工具包，提供libvirt服务</p>
</li>
<li><p>virt-install ： 基于libvirt服务的虚拟机创建命令</p>
</li>
<li><p>python-virtinst ： 创建虚拟机所需要的命令行工具和程序库</p>
</li>
<li><p>bridge-utils ： 创建和管理桥接设备的工具</p>
</li>
</ul>
<p>确认安装成功</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@lt ~]<span class="comment"># lsmod |grep kvm # KVm环境</span></span><br><span class="line">kvm_intel             170086  0 </span><br><span class="line">kvm                   566340  1 kvm_intel</span><br><span class="line">irqbypass              13503  1 kvm</span><br></pre></td></tr></table></figure>

<p>启动libvirt服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">[root@lt ~]<span class="comment"># service libvirtd start  # 启动libvirt服务</span></span><br><span class="line">Redirecting to /bin/systemctl start libvirtd.service</span><br><span class="line">[root@lt ~]<span class="comment"># service libvirtd status # 查询libvirt状态</span></span><br><span class="line">Redirecting to /bin/systemctl status libvirtd.service</span><br><span class="line">● libvirtd.service - Virtualization daemon</span><br><span class="line">   Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)</span><br><span class="line">   Active: active (running) since 日 2021-08-22 19:32:49 CST; 6s ago</span><br><span class="line">     Docs: man:libvirtd(8)</span><br><span class="line">           https://libvirt.org</span><br><span class="line"> Main PID: 3800 (libvirtd)</span><br><span class="line">    Tasks: 19 (<span class="built_in">limit</span>: 32768)</span><br><span class="line">   CGroup: /system.slice/libvirtd.service</span><br><span class="line">           ├─3800 /usr/sbin/libvirtd</span><br><span class="line">           ├─3899 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper</span><br><span class="line">           └─3900 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper</span><br><span class="line"></span><br><span class="line">8月 22 19:32:50 lt dnsmasq[3899]: started, version 2.76 cachesize 150</span><br><span class="line">8月 22 19:32:50 lt dnsmasq[3899]: compile time options: IPv6 GNU-getopt DBus no-i18n IDN DHCP DHCPv6 no-Lua TFTP no-conntrack ipset auth nettlehash no-DNSSEC loop-detect inotify</span><br><span class="line">8月 22 19:32:50 lt dnsmasq-dhcp[3899]: DHCP, IP range 192.168.122.2 -- 192.168.122.254, lease time 1h</span><br><span class="line">8月 22 19:32:50 lt dnsmasq-dhcp[3899]: DHCP, sockets bound exclusively to interface virbr0</span><br><span class="line">8月 22 19:32:50 lt dnsmasq[3899]: reading /etc/resolv.conf</span><br><span class="line">8月 22 19:32:50 lt dnsmasq[3899]: using nameserver 192.168.1.1<span class="comment">#53</span></span><br><span class="line">8月 22 19:32:50 lt dnsmasq[3899]: using nameserver fe80::1%eth0<span class="comment">#53</span></span><br><span class="line">8月 22 19:32:50 lt dnsmasq[3899]: <span class="built_in">read</span> /etc/hosts - 2 addresses</span><br><span class="line">8月 22 19:32:50 lt dnsmasq[3899]: <span class="built_in">read</span> /var/lib/libvirt/dnsmasq/default.addnhosts - 0 addresses</span><br><span class="line">8月 22 19:32:50 lt dnsmasq-dhcp[3899]: <span class="built_in">read</span> /var/lib/libvirt/dnsmasq/default.hostsfile</span><br></pre></td></tr></table></figure>

<p>kvm，只是Linux内核的一个模块，不需要安装，只需要加载，加载命令如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@lt ~]<span class="comment"># modprobe kvm</span></span><br><span class="line">[root@lt ~]<span class="comment"># modprobe kvm_intel</span></span><br></pre></td></tr></table></figure>

<p>也可以<strong>重启系统</strong>后使用如下命令加载KVM模块：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@lt ~]<span class="comment"># virsh -c qemu:///system list  # 出现次列表说明KVM安装成功，方便保存虚拟机快照，若执行失败重启后再执行</span></span><br><span class="line"> Id    名称                         状态</span><br><span class="line">----------------------------------------------------</span><br><span class="line">[root@lt ~]<span class="comment"># mkdir -p /usr/local/bin/kvm/iso # 创建kvm工作环境，将iso目录存放系统镜像文件</span></span><br><span class="line">[root@lt ~]<span class="comment"># mkdir -p /usr/local/bin/kvm/vhdx # 创建kvm工作环境，将vhdx目录虚拟硬盘</span></span><br></pre></td></tr></table></figure>

<h2 id="3-4-KVM管理"><a href="#3-4-KVM管理" class="headerlink" title="3.4 KVM管理"></a>3.4 KVM管理</h2><ul>
<li>查看virsh帮助文档：virsh –help </li>
<li>查看所有虚拟机：virsh list   –all</li>
<li>查看正在运行的虚拟机：virsh -c qemu:///system list</li>
<li>启动虚拟机：virsh start vm-name</li>
<li>关闭虚拟机：virsh shutdown vm-name</li>
<li>强制断电关机：virsh destroy vm-name</li>
<li>挂起虚拟机：virsh suspend vm-name</li>
<li>恢复挂起虚拟机：virsh resume vm-name</li>
<li>删除虚拟机：virsh undefine  vm-name</li>
<li>查看虚拟机VNC：virsh vncdisplay vm-name</li>
<li>查看当前虚拟机网卡信息：virsh domiflist vm-name</li>
<li>查看当前虚拟机信息：virsh dominfo vm-name</li>
<li>开机自启虚拟机：virsh autostart vm-name                     # 配置后会在此目录生成配置文件/etc/libvirt/qemu/autostart/vm-name.xml                              </li>
<li>取消开机自启虚拟机：virsh autostart –disable vm-name</li>
<li>查看当前虚拟机当前配置信息：virsh dumpxml vm-name</li>
<li>编辑虚拟机配置信息：virsh edit vm-name</li>
<li>备份当前运行虚拟机的配置信息：virsh dumpxml vm-name &gt; vm-name.bak.xml   # 原文件默认路径/etc/libvirt/qemu/vm-name.xml</li>
<li>查看虚拟机磁盘位置：irsh domblklist vm-name </li>
</ul>
<h1 id="4-小牛试刀"><a href="#4-小牛试刀" class="headerlink" title="4. 小牛试刀"></a>4. 小牛试刀</h1><h2 id="4-1-Windows-10虚拟化安装"><a href="#4-1-Windows-10虚拟化安装" class="headerlink" title="4.1 Windows 10虚拟化安装"></a>4.1 Windows 10虚拟化安装</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@lt kvm]<span class="comment"># ll /usr/local/bin/kvm/iso/   # 将下载好的win10 iso镜像存放在此目录，镜像名称可以自定义</span></span><br><span class="line">总用量 5671560</span><br><span class="line">-rw-r--r--. 1 qemu qemu 5807677440 8月  24 19:51 win10.iso</span><br></pre></td></tr></table></figure>

<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br></pre></td><td class="code"><pre><span class="line">[root@lt kvm]<span class="comment"># qemu-img create -f qcow2 /usr/local/bin/kvm/vhdx/win10.img 100G # # 创建一个100G的qcow2格式并且名为win10的磁盘镜像，注意尽量使用可动态扩容的qcow2格式，而不是使用raw格式</span></span><br><span class="line">Formatting <span class="string">&#x27;/usr/local/bin/kvm/vhdx/win10.img&#x27;</span>, <span class="built_in">fmt</span>=qcow2 size=107374182400 encryption=off cluster_size=65536 lazy_refcounts=off</span><br><span class="line">[root@lt kvm]<span class="comment"># ll /usr/local/bin/kvm/vhdx/win10.img # 生成磁盘镜像文件</span></span><br><span class="line">-rw-r--r--. 1 root root 197120 8月  22 20:34 /usr/local/bin/kvm/vhdx/win10.img</span><br><span class="line">[root@lt kvm]<span class="comment"># qemu-img info /usr/local/bin/kvm/vhdx/win10.img</span></span><br><span class="line">image: /usr/local/bin/kvm/vhdx/win10.img</span><br><span class="line">file format: qcow2</span><br><span class="line">virtual size: 30G (32212254720 bytes)</span><br><span class="line">disk size: 196K</span><br><span class="line">cluster_size: 65536</span><br><span class="line">Format specific information:</span><br><span class="line">    compat: 1.1</span><br><span class="line">    lazy refcounts: <span class="literal">false</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">[root@lt ~]<span class="comment"># brctl show   # 查看虚拟机网络，安装完KVM会创建一个virbr0的虚拟网卡，默认是NAT模式，注意这里的bridge不是所谓的桥接</span></span><br><span class="line">bridge name	bridge <span class="built_in">id</span>		STP enabled	interfaces</span><br><span class="line">virbr0		8000.525400f2921f	<span class="built_in">yes</span>		virbr0-nic</span><br><span class="line">[root@lt ~]<span class="comment"># virsh net-list</span></span><br><span class="line"> 名称               状态     自动开始  持久</span><br><span class="line">----------------------------------------------------------</span><br><span class="line"> default              活动     是           是</span><br><span class="line"> </span><br><span class="line">[root@lt ~]<span class="comment"># virsh net-destroy default   # 删除默认网络</span></span><br><span class="line">网络 default 被删除</span><br><span class="line">[root@lt ~]<span class="comment"># virsh net-undefine default  # 取消默认网络定义</span></span><br><span class="line">网络 default 已经被取消定义</span><br><span class="line">[root@lt ~]<span class="comment">#service libvirtd restart  # 重启libvirtd服务</span></span><br><span class="line">Redirecting to /bin/systemctl restart libvirtd.service</span><br><span class="line">[root@lt ~]<span class="comment">#  virsh net-list  # 查看是否删除默认网络</span></span><br><span class="line"> 名称               状态     自动开始  持久</span><br><span class="line">----------------------------------------------------------</span><br><span class="line">[root@lt ~]<span class="comment"># brctl  show      # 确认默认网络已被删除</span></span><br><span class="line">bridge name	bridge <span class="built_in">id</span>		STP enabled	interfaces</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">[root@lt ~]<span class="comment"># service network restart</span></span><br><span class="line">Restarting network (via systemctl):                        [  确定  ]</span><br><span class="line"></span><br><span class="line">[root@lt ~]<span class="comment"># brctl show</span></span><br><span class="line">bridge name	bridge <span class="built_in">id</span>		STP enabled	interfaces</span><br><span class="line">br0		8000.00155d565001	no		eth0</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line">[root@lt kvm]<span class="comment"># virt-install --virt-type kvm --name win10_64 --memory 8192 --cdrom=/usr/local/bin/kvm/iso/win10.iso --boot cdrom --disk path=/usr/local/bin/kvm/vhdx/win10.img,bus=&#x27;ide&#x27; --network bridge=br0 --graphics vnc,password=123456,port=5900,listen=0.0.0.0,keymap=us  --vcpus 5 --noautoconsole --os-type=windows   # 创建Windows 10虚拟机,并设置为桥接网络</span></span><br><span class="line"></span><br><span class="line">开始安装......</span><br><span class="line">域安装仍在进行。您可以重新连接</span><br><span class="line">到控制台以便完成安装进程。</span><br><span class="line">[root@lt kvm]<span class="comment"># virsh list   --all   # 列出所有虚拟机</span></span><br><span class="line"> Id    名称                         状态</span><br><span class="line">----------------------------------------------------</span><br><span class="line"> 5     win10_64                       running</span><br><span class="line"></span><br><span class="line">[root@lt kvm]<span class="comment"># virsh -c qemu:///system list  # 列出当前启动的虚拟机</span></span><br><span class="line"> Id    名称                         状态</span><br><span class="line">----------------------------------------------------</span><br><span class="line"> 5     win10_64                       running</span><br><span class="line"> </span><br><span class="line"></span><br><span class="line">[root@lt kvm]<span class="comment"># systemctl stop firewalld  # 关闭防火墙，因为要访问vnc的5910端口</span></span><br><span class="line"></span><br><span class="line">[root@localhost vhdx]<span class="comment"># virsh domiflist centos7</span></span><br><span class="line">接口     类型     源        型号      MAC</span><br><span class="line">-------------------------------------------------------</span><br><span class="line">vnet0      bridge     br0        virtio      52:54:00:67:1b:51</span><br><span class="line"></span><br><span class="line">[root@localhost vhdx]<span class="comment"># virsh attach-interface centos7 --type bridge --source br0</span></span><br><span class="line">成功附加接口</span><br><span class="line"></span><br><span class="line">[root@localhost vhdx]<span class="comment"># virsh domiflist centos7</span></span><br><span class="line">接口     类型     源        型号      MAC</span><br><span class="line">-------------------------------------------------------</span><br><span class="line">vnet0      bridge     br0        virtio      52:54:00:67:1b:51</span><br><span class="line">vnet1      bridge     br0        rtl8139     52:54:00:e9:d3:f4</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><img src="https://ltyeamin.github.io/imgs/2021/08/20210825112508.png" alt="使用VNC View工具连接"></p>
<p><img src="https://ltyeamin.github.io/imgs/2021/08/20210825112804.png" alt="连接成功"></p>
<p><img src="https://ltyeamin.github.io/imgs/2021/08/20210825125044.png" alt="安裝Windows"></p>
<h2 id="4-2-Linux-CentOS-7虚拟化安装"><a href="#4-2-Linux-CentOS-7虚拟化安装" class="headerlink" title="4.2 Linux CentOS 7虚拟化安装"></a>4.2 Linux CentOS 7虚拟化安装</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">[root@lt iso]<span class="comment"># ll /usr/local/bin/kvm/iso/   # 上传CentOS7镜像</span></span><br><span class="line">总用量 10087048</span><br><span class="line">-rw-r--r--. 1 root root 4521459712 8月  25 18:58 centos7.iso</span><br><span class="line">-rw-r--r--. 1 qemu qemu 5807677440 8月  24 19:51 win10.iso</span><br><span class="line"></span><br><span class="line">[root@lt kvm]<span class="comment"># qemu-img create -f qcow2 /usr/local/bin/kvm/vhdx/centos7.img 30G  # 创建30G的虚拟硬盘</span></span><br><span class="line">Formatting <span class="string">&#x27;/usr/local/bin/kvm/vhdx/centos7.img&#x27;</span>, <span class="built_in">fmt</span>=qcow2 size=32212254720 encryption=off cluster_size=65536 lazy_refcounts=off</span><br><span class="line"></span><br><span class="line">[root@lt kvm]<span class="comment"># osinfo-query os # 列出可选的操作系统，方便设置下面--os-variant的参数 --boot hd,cdrom,menu=on </span></span><br><span class="line">[root@lt kvm]<span class="comment"># virt-install -n centos7 -r 4096 --vcpus 4 --disk path=/usr/local/bin/kvm/vhdx/centos7.qcow2,size=20,format=qcow2,bus=virtio --network bridge=br0,model=virtio --os-type linux --os-variant rhel7 --cdrom=/usr/local/bin/kvm/iso/centos7.iso --graphics vnc,password=123456,port=5903,listen=0.0.0.0,keymap=us --boot hd --noautoconsole   # 创建CentOS7虚拟机,并设置为桥接网络，</span></span><br><span class="line">开始安装......</span><br><span class="line">域安装仍在进行。您可以重新连接</span><br><span class="line">到控制台以便完成安装进程。</span><br></pre></td></tr></table></figure>

<p><img src="https://ltyeamin.github.io/imgs/2021/08/20210825191529.png"></p>
<p><img src="https://ltyeamin.github.io/imgs/2021/08/20210825191607.png"></p>
<p><img src="https://ltyeamin.github.io/imgs/2021/08/20210825191928.png"></p>
<p><img src="https://ltyeamin.github.io/imgs/2021/08/20210825192022.png"></p>
<p><img src="https://ltyeamin.github.io/imgs/2021/08/20210825195216.png"></p>
<p><img src="https://ltyeamin.github.io/imgs/2021/08/20210826111554.png"></p>
<h2 id="4-3-Mac-OS-虚拟化安装"><a href="#4-3-Mac-OS-虚拟化安装" class="headerlink" title="4.3 Mac OS 虚拟化安装"></a>4.3 Mac OS 虚拟化安装</h2><p>需要注意两点：</p>
<ul>
<li>CPU必须是英特尔公司的芯片，前面说过虚拟化对英特尔公司的CPU支持性很好</li>
<li>虚拟化的CPU、内存、磁盘尽量高配置</li>
</ul>
<img src="https://ltyeamin.github.io/imgs/2021/09/20210902142339.png" style="zoom:80%;" />



<img src="https://ltyeamin.github.io/imgs/2021/09/20210902142404.png" style="zoom:80%;" />



<img src="https://ltyeamin.github.io/imgs/2021/09/20210902142453.png" style="zoom:80%;" />



<img src="https://ltyeamin.github.io/imgs/2021/09/20210902142805.png" style="zoom:80%;" />



<p>具体安装请参考<a target="_blank" rel="noopener" href="https://github.com/kholia/OSX-KVM%E5%92%8Chttps://github.com/foxlet/macOS-Simple-KVM%EF%BC%8C%E8%BF%99%E9%87%8C%E4%B8%8D%E5%81%9A%E9%87%8D%E7%82%B9%E5%B1%95%E5%BC%80%E5%AE%89%E8%A3%85%E3%80%82">https://github.com/kholia/OSX-KVM和https://github.com/foxlet/macOS-Simple-KVM，这里不做重点展开安装。</a></p>
<h1 id="5-参考文档"><a href="#5-参考文档" class="headerlink" title="5. 参考文档"></a>5. 参考文档</h1><ul>
<li><a target="_blank" rel="noopener" href="http://www.linux-kvm.org/page/Documents">KVM官方文档</a></li>
<li><a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/%E5%9F%BA%E4%BA%8E%E5%86%85%E6%A0%B8%E7%9A%84%E8%99%9A%E6%8B%9F%E6%9C%BA">KVM维基百科</a></li>
<li><a target="_blank" rel="noopener" href="https://www.cnblogs.com/heyongboke/p/10337447.html">KVM网络桥接</a></li>
<li><a target="_blank" rel="noopener" href="https://blog.csdn.net/hzhsan/article/details/44098537/">KVM网络桥接设置</a></li>
<li><a target="_blank" rel="noopener" href="http://www.linuxcoming.com/blog/2019/09/03/linux_basic_tools_virt_install_os_variant.html">KVM支持的操作系统</a></li>
<li><a target="_blank" rel="noopener" href="https://www.cnblogs.com/bigdevilking/p/9615261.html">命令行安裝CentOS7</a></li>
<li><a target="_blank" rel="noopener" href="https://blog.51cto.com/zero01/2083896">KVM安裝CentOS7</a></li>
<li><a target="_blank" rel="noopener" href="https://www.pianshen.com/article/3892687143/">KVM图形界面安装CentOS7</a></li>
<li><a target="_blank" rel="noopener" href="https://www.realvnc.com/en/connect/download/vnc/">RealVNC远程桌面连接工具</a></li>
<li><a target="_blank" rel="noopener" href="https://www.tightvnc.com/">TightVNC远程桌面连接工具</a></li>
<li><a target="_blank" rel="noopener" href="https://tigervnc.org/">TigerVNC远程桌面工具</a></li>
</ul>
</section>
    <!-- Tags START -->
    
      <div class="tags">
        <span>Tags:</span>
        
  <a href="/tags#Linux" >
    <span class="tag-code">Linux</span>
  </a>

      </div>
    
    <!-- Tags END -->
    <!-- NAV START -->
    
  <div class="nav-container">
    <!-- reverse left and right to put prev and next in a more logic postition -->
    
      <a class="nav-left" href="/2021/08/03/Linux%E5%9F%BA%E7%A1%80-%E9%80%9A%E8%BF%87inode%E5%88%A0%E9%99%A4%E6%96%87%E4%BB%B6/">
        <span class="nav-arrow">← </span>
        
          Linux基础-通过inode删除文件
        
      </a>
    
    
      <a class="nav-right" href="/2021/09/04/Spring%20Boot%E5%88%9D%E5%A7%8B%E5%8C%96%E7%9A%84%E9%82%A3%E7%82%B9%E4%BA%8B/">
        
          Spring Boot初始化的那点事
        
        <span class="nav-arrow"> →</span>
      </a>
    
  </div>

    <!-- NAV END -->
    <!-- 打赏 START -->
    
      <div class="money-like">
        <div class="reward-btn">
          赏
          <span class="money-code">
            <span class="alipay-code">
              <div class="code-image"></div>
              <b>使用支付宝打赏</b>
            </span>
            <span class="wechat-code">
              <div class="code-image"></div>
              <b>使用微信打赏</b>
            </span>
          </span>
        </div>
        <p class="notice">若你觉得我的文章对你有帮助，欢迎点击上方按钮对我打赏</p>
      </div>
    
    <!-- 打赏 END -->
    <!-- 二维码 START -->
    
      <div class="qrcode">
        <canvas id="share-qrcode"></canvas>
        <p class="notice">扫描二维码，分享此文章</p>
      </div>
    
    <!-- 二维码 END -->
    
      <!-- Utterances START -->
      <div id="utterances"></div>
      <script src="https://utteranc.es/client.js"
        repo="ltyeamin/blogtalks"
        issue-term="pathname"
        theme="github-light"
        crossorigin="anonymous"
        async></script>    
      <!-- Utterances END -->
    
  </article>
  <!-- Article END -->
  <!-- Catalog START -->
  
    <aside class="catalog-container">
  <div class="toc-main">
    <strong class="toc-title">Catalog</strong>
    
      <ol class="toc-nav"><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#1-%E4%B8%BB%E6%B5%81%E8%99%9A%E6%8B%9F%E5%8C%96%E4%BA%A7%E5%93%81"><span class="toc-nav-text">1. 主流虚拟化产品</span></a></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#2-KVM%E8%99%9A%E6%8B%9F%E5%8C%96"><span class="toc-nav-text">2. KVM虚拟化</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#2-1-%E5%8F%91%E5%B1%95%E5%8E%86%E7%A8%8B"><span class="toc-nav-text">2.1 发展历程</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#2-2-%E6%A8%A1%E5%9D%97%E6%9E%B6%E6%9E%84"><span class="toc-nav-text">2.2 模块架构</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#2-3-%E5%9B%BE%E5%BD%A2%E7%AE%A1%E7%90%86%E5%B7%A5%E5%85%B7"><span class="toc-nav-text">2.3  图形管理工具</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#3-KVM%E5%B9%B3%E5%8F%B0%E6%90%AD%E5%BB%BA"><span class="toc-nav-text">3. KVM平台搭建</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#3-1-%E6%9C%BA%E5%99%A8%E5%88%97%E8%A1%A8"><span class="toc-nav-text">3.1 机器列表</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#3-2-%E8%99%9A%E6%8B%9F%E5%8C%96%E6%94%AF%E6%8C%81"><span class="toc-nav-text">3.2 虚拟化支持</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#3-2-1-Linux%E5%B9%B3%E5%8F%B0"><span class="toc-nav-text">3.2.1 Linux平台</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#3-2-2-Windows%E5%B9%B3%E5%8F%B0"><span class="toc-nav-text">3.2.2 Windows平台</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#3-2-2-1-%E4%BB%BB%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8-%E6%80%A7%E8%83%BD%E9%80%89%E9%A1%B9%E6%9F%A5%E7%9C%8B"><span class="toc-nav-text">3.2.2.1 任务管理器-性能选项查看</span></a></li><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#3-2-2-2-Hyper-V%E8%AE%BE%E7%BD%AE%E5%B5%8C%E5%A5%97%E8%99%9A%E6%8B%9F%E5%8C%96%E6%94%AF%E6%8C%81"><span class="toc-nav-text">3.2.2.2 Hyper-V设置嵌套虚拟化支持</span></a></li></ol></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#3-3-%E5%AE%89%E8%A3%85%E7%8E%AF%E5%A2%83"><span class="toc-nav-text">3.3 安装环境</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#3-4-KVM%E7%AE%A1%E7%90%86"><span class="toc-nav-text">3.4 KVM管理</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#4-%E5%B0%8F%E7%89%9B%E8%AF%95%E5%88%80"><span class="toc-nav-text">4. 小牛试刀</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#4-1-Windows-10%E8%99%9A%E6%8B%9F%E5%8C%96%E5%AE%89%E8%A3%85"><span class="toc-nav-text">4.1 Windows 10虚拟化安装</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#4-2-Linux-CentOS-7%E8%99%9A%E6%8B%9F%E5%8C%96%E5%AE%89%E8%A3%85"><span class="toc-nav-text">4.2 Linux CentOS 7虚拟化安装</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#4-3-Mac-OS-%E8%99%9A%E6%8B%9F%E5%8C%96%E5%AE%89%E8%A3%85"><span class="toc-nav-text">4.3 Mac OS 虚拟化安装</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#5-%E5%8F%82%E8%80%83%E6%96%87%E6%A1%A3"><span class="toc-nav-text">5. 参考文档</span></a></li></ol>
    
  </div>
</aside>
  
  <!-- Catalog END -->
</main>

<script>
  (function () {
    var url = 'http://example.com/2021/08/22/Linux虚拟化-KVM服务器虚拟化技术/';
    var banner = ''
    if (banner !== '' && banner !== 'undefined' && banner !== 'null') {
      $('#article-banner').css({
        'background-image': 'url(' + banner + ')'
      })
    } else {
      $('#article-banner').geopattern(url)
    }
    $('.header').removeClass('fixed-header')

    // error image
    $(".markdown-content img").on('error', function() {
      $(this).attr('src', '/css/images/error_icon.png')
      $(this).css({
        'cursor': 'default'
      })
    })

    // zoom image
    $(".markdown-content img").on('click', function() {
      var src = $(this).attr('src')
      if (src !== '/css/images/error_icon.png') {
        var imageW = $(this).width()
        var imageH = $(this).height()

        var zoom = ($(window).width() * 0.95 / imageW).toFixed(2)
        zoom = zoom < 1 ? 1 : zoom
        zoom = zoom > 2 ? 2 : zoom
        var transY = (($(window).height() - imageH) / 2).toFixed(2)

        $('body').append('<div class="image-view-wrap"><div class="image-view-inner"><img src="'+ src +'" /></div></div>')
        $('.image-view-wrap').addClass('wrap-active')
        $('.image-view-wrap img').css({
          'width': `${imageW}`,
          'transform': `translate3d(0, ${transY}px, 0) scale3d(${zoom}, ${zoom}, 1)`
        })
        $('html').css('overflow', 'hidden')

        $('.image-view-wrap').on('click', function() {
          $(this).remove()
          $('html').attr('style', '')
        })
      }
    })
  })();
</script>


  <script>
    var qr = new QRious({
      element: document.getElementById('share-qrcode'),
      value: document.location.href
    });
  </script>






    <div class="scroll-top">
  <span class="arrow-icon"></span>
</div>
    <footer class="app-footer">
  <p class="copyright">
    &copy; 2024 | Proudly powered by <a href="https://hexo.io" target="_blank">Hexo</a>
    <br>
    Theme by <a target="_blank" rel="noopener" href="https://github.com/ltyeamin">tong.li</a>
  </p>
</footer>

<script>
  function async(u, c) {
    var d = document, t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    o.src = u;
    if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
    s.parentNode.insertBefore(o, s);
  }
</script>
<script>
  async("https://cdn.staticfile.org/fastclick/1.0.6/fastclick.min.js", function(){
    FastClick.attach(document.body);
  })
</script>

<script>
  var hasLine = 'true';
  async("https://cdn.staticfile.org/highlight.js/9.12.0/highlight.min.js", function(){
    $('figure pre').each(function(i, block) {
      var figure = $(this).parents('figure');
      if (hasLine === 'false') {
        figure.find('.gutter').hide();
      }
      hljs.configure({useBR: true});
      var lang = figure.attr('class').split(' ')[1] || 'code';
      var codeHtml = $(this).html();
      var codeTag = document.createElement('code');
      codeTag.className = lang;
      codeTag.innerHTML = codeHtml;
      $(this).attr('class', '').empty().html(codeTag);
      figure.attr('data-lang', lang.toUpperCase());
      hljs.highlightBlock(block);
    });
  })
</script>
<!-- Baidu Tongji -->



<script src='https://cdn.staticfile.org/mermaid/8.11.2/mermaid.min.js'></script>



<script src="/js/script.js"></script>


  </body>
</html>